#include <iostream>
#define MIN(A,B) A<B?A:B

using namespace std;

int main(){
	int capacity;
	int itemNum;
	int last[20001];
	int itemCap[31];
	cin >> capacity >> itemNum;
	for(int i = 1; i <= itemNum; i++)
		cin >> itemCap[i];
	for(int i = 0; i <= capacity; i++)
		last[i] = i;
	for(int i = 1; i <= itemNum; i++){
		for(int j = capacity; j >= 1; j--){
			if(j >= itemCap[i]) last[j] = MIN(last[j], last[j-itemCap[i]]);
		}
	}
	cout << last[capacity] << endl;
}
